<template>
  <div>
    <!-- 导航栏 -->
    <van-nav-bar
      title="文章详情"
      left-arrow
      fixed
      placeholder
      @click-left="$router.back()"
    ></van-nav-bar>

    <div class="box">
      <!-- 标题 -->
      <h2 class="title">{{ info.title }}</h2>
      <!-- 作者资料区域 -->
      <div class="aut-box">
        <!-- 图片 -->
        <van-image class="avatar" round fit="cover" :src="info.aut_photo" />
        <!-- 作者名字与时间 -->
        <div class="info-box">
          <div class="name">{{ info.aut_name }}</div>
          <span class="time">{{ info.pubdate | relvTime }}</span>
        </div>
        <!-- 按钮 -->
        <van-button icon="plus" type="info" round size="small">关注</van-button>
      </div>
      <!-- 内容区域 -->
      <div v-html="info.content" class="content"></div>
    </div>

    <!-- 评论 -->
    <my-comment></my-comment>
  </div>
</template>

<script>
import { detailAPI } from '@/api/article'
import MyComment from './components/MyComment.vue'
export default {
  name: 'MyArticle',
  components: {
    MyComment
  },
  data () {
    return {
      info: {}
    }
  },
  async created () {
    const res = await detailAPI(this.$route.params.id)
    this.info = res.data
  }
}
</script>

<style lang="less" scoped>
.box {
  padding: 15px;
  .title {
    font-size: 20px;
  }
  .aut-box {
    display: flex;
    height: 140px;
    align-items: center;
    .avatar {
      width: 100px;
      height: 100px;
    }

    .info-box {
      margin-left: 15px;
      flex: 1;
      .name {
        margin-bottom: 10px;
      }
      .time {
        color: gray;
        font-size: 12px;
      }
    }
  }

  .content {
    ::v-deep {
      pre {
        display: inline-block;
        width: 100%;
        overflow: auto;
        background-color: #000;
        color: gray;
        code {
          display: inline-block;
          width: 100%;
          overflow: auto;
          background-color: #000;
          color: gray;
        }
      }

      img {
        width: 100%;
      }
    }
  }
}
</style>
